﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SysRouteLinq.Forms
{
    public partial class EditEmpresa : Form
    {
        private SysRouteDataContext dc;
        private int idEmpresa;
        private Empresa r;

        public EditEmpresa(int aIdEmpresa)
        {
            InitializeComponent();
            dc = new SysRouteDataContext();
            idEmpresa = aIdEmpresa;
            r = (from f in dc.Empresas
                 where
                 f.id_empresa == idEmpresa
                 select f).Single();
            textBox1.Text = r.nome;
            textBox2.Text = r.CNPJ;
            textBox3.Text = r.endereco;
            textBox4.Text = r.telefone;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            r.nome = textBox1.Text;
            r.CNPJ = textBox2.Text;
            r.endereco = textBox3.Text;
            r.telefone = textBox4.Text;
            dc.SubmitChanges();
            MessageBox.Show("Alteração realizada com sucesso!");
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}
